package com.atguigu.gmall.item.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Aupt
 * @create 2022-06-06-9:48
 */
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ExecutorService executorService(
            @Value("${threadPool.corPoolSize}") Integer corPoolSize,
            @Value("${threadPool.maximumSize}") Integer maximumSize,
            @Value("${threadPool.keepAliveTime}") Integer keepAliveTime,
            @Value("${threadPool.blockingQueueSize}") Integer blockingQueueSize
    ) {

        return new ThreadPoolExecutor(corPoolSize, maximumSize, keepAliveTime, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(blockingQueueSize));
    }

}
